﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.IO;
using System.Windows.Forms;

namespace LDTB.Service
{
    class DataService
    {
        private static LDTBDataDataContext _DB = null;

        private const string XML_FILE_NAME = "ConfigAppObject.xml";

        public static string StrCnn
        {
            get
            {
                string cnn;
                TextReader f = new StreamReader("Config.txt");
                try
                {

                    cnn = f.ReadToEnd();
                }
                finally
                {
                    f.Close();
                }

                return cnn;
            }
        }



        public static LDTBDataDataContext DB
        {
            get
            {
                if (_DB == null)
                {

                    _DB = new LDTBDataDataContext(StrCnn);
                }
                return DataService._DB;

            }
        }

        public static ConfigApp GetConfig()
        {
            // Load the customer object from the XML file using our custom class...
            ConfigApp config = ObjectXMLSerializer<ConfigApp>.Load(XML_FILE_NAME);

            return config;

        }

        public void SetConfig(ConfigApp cf)
        {

            ObjectXMLSerializer<ConfigApp>.Save(cf, XML_FILE_NAME);

        }

    }
}
